public class p1 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		int target = 1000;
		int sum = 0;

		// naive method
		for (int i = 1; i < target; i++) {
			if (i % 3 == 0 || i % 5 == 0) {
				sum += i;
				// System.out.println(i);
			}
		}
		System.out.println(sum);

		// advanced method
		System.out.println(SumDivisibleByN(target - 1, 3)
				+ SumDivisibleByN(target - 1, 5)
				- SumDivisibleByN(target - 1, 15));
	}

	static int SumDivisibleByN(int target, int N) {
		int p = target / N;
		return N * p * (p + 1) / 2;
	}
}
